﻿<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>网站标题</title>
<script type="text/javascript" src="/js/lib/jquery-1.6.4.min.js"></script>
</head>
<body>

<!--dom-->
<img src="../../images/AD.jpg" id="demo"/>
<input type="button" value="保存" id="saveBtn">
<input type="button" value="打印" id="pointBtn">
<!--/dom-->
	

<script type="text/javascript">
$(function(){
	//图像保存
	imageSave({
		url:$("#demo").attr("src"),
		root:"#saveBtn"
	});
	//图像打印
	imagePoint({
		url:$("#demo").attr("src"),
		root:"#pointBtn"
	});
})

<!--javascript-->
/**
 @author wj
 @title 保存
 @param config json Object
 @demo
 imageSave({
	url:"",//必填 需要保存/打印的图片路径
	root:".imageSave",//需要绑定方法的jquery 选择符 默认imageSave
	width:"",//弹出的iframe宽 默认300
	height:""//弹出的iframe高 默认300
 });
*/
function imageSave(config) {
	var config = config || {};
	var root = config.root || ".imageSave";
	var width = config.width || "300";
	var height = config.height || "300";
		$(root).click(function(){	
		var $obj = $(this);
		var url = config.url || $obj.attr('href');	
		var curimgsrc = url;
		var myWindow = window.open('','','width='+width+',height='+height+'');
		myWindow.document.write('<img src="'+curimgsrc+'"/>');
		myWindow.document.execCommand("SaveAs"); 
		myWindow.document.close();
		return false;
	});
}
/**
 @author wj
 @title 打印
 @param config json Object
 @demo
 imagePoint({
	url:"",//必填 需要保存/打印的图片路径
	root:".imagePoint",//需要绑定方法的jquery 选择符 默认imagePoint
	width:"",//弹出的iframe宽 默认300
	height:""//弹出的iframe高 默认300
 });
*/
function imagePoint(config){
	var config = config || {};
	var root = config.root || ".imagePoint";
	var width = config.width || "300";
	var height = config.height || "300";
	$(root).click(function(){		
		var $obj = $(this);
		var url = config.url || $obj.attr('href');	
		var curimgsrc = url;
		var myWindow = window.open('','','width='+width+',height='+height+'');
		myWindow.document.write('<img src="'+curimgsrc+'"/>');
		myWindow.print();
		myWindow.document.close();
		return false;
	});
}
<!--/javascript-->
</script>
</body>
</html>



